package main

import (
	"fmt"
	"net/http"
	"time"
)

func mirroredQuery() string {
	responses := make(chan string, 3)
	go func() {
		responses <- request("https://www.baidu.com")
	}()
	go func() {
		responses <- request("https://www.taobao.com")
	}()
	go func() {
		responses <- request("https://www.jd.com")
	}()
	fmt.Println("cap(responses) : ", cap(responses))
	fmt.Println("len(responses) : ", len(responses))
	return <-responses
}

func request(url string) (take string) {
	start := time.Now()
	resp, _ := http.Get(url)
	if http.StatusOK == resp.StatusCode {
		fmt.Println(resp.Status)
	}
	end := time.Now()
	return fmt.Sprintf("%s : 耗时 %d ms", url, end.Sub(start).Milliseconds())
}

func main() {
	query := mirroredQuery()
	fmt.Println(query)
}
